<template>
  <div>
    <van-checkbox-group v-model="selectArr">
      <van-list v-model:loading="loading" :finished="finished" :finished-text="list.length>0 ? '没有更多了':''" @load="onLoad">
        <div class="L-box">
          <van-row type="flex" v-for="(item,index) in list" :key="index">
            <van-col :span="18">
              <div class="L-text L-bold" v-html="item.title"></div>
              <div class="L-secondary-text-color L-small-text" v-html="item.label"></div>
            </van-col>
            <van-col :span="6">
              <div v-if="item.value" style="text-align: right;">
                <span class="L-secondary-text-color L-small-text" v-html="item.value"></span>
              </div>
              <div style="text-align: right;display: flex;justify-content: end;margin-top:20px">
                <van-checkbox :name="item.id"></van-checkbox>
              </div>
            </van-col>
          </van-row>
        </div>
      </van-list>
    </van-checkbox-group>

    <div class="L-bottom-space"></div>
    <van-sticky position="bottom">
      <div class="L-bottom-row">
        <!-- <van-button round type="default" style="width:40%" @click="r">取消</van-button> -->
        <van-button round type="primary" style="width:80%" @click="handleConfirm">确定</van-button>
      </div>
    </van-sticky>

  </div>
</template>

<script setup lang="ts">
import { closeToast, showLoadingToast } from "vant";
import { apiConfigurable } from "@/request/api/api";
import { useRouter, useRoute } from "vue-router";
const router = useRouter();
const route = useRoute();
import BaseList from "@/components/base/List/BaseList.vue";
import { ref } from "vue";

const selectArr = ref([]);
const loadapi = `${route.query.idobject as string}.sdlistsub.do`;
const list = ref([]);
const startline = ref(1);
const pagecount = ref(50); //每页条数
const loading = ref(false); //是否加载中
const finished = ref(false); //列表是否加载完成

function onLoad() {
  const { idobject, sdtype, subviewid, subrefobject, relopeid, headid } =
    route.query;
  let data = {
    startline: startline.value,
    pagecount: pagecount.value,
    sdtype,
    subviewid,
    subrefobject,
    relopeid,
    headid,
  };

  showLoadingToast({
    message: "加载中...",
    forbidClick: true,
    duration: 0,
  });

  loading.value = true;
  apiConfigurable(loadapi, data).then((res) => {
    if (res.data?.jsondata?.fieldValue.length < pagecount.value) {
      finished.value = true;
    }
    list.value = [...list.value, ...res.data?.jsondata?.fieldValue];
    startline.value = list.value.length + 1;
    closeToast();
    loading.value = false;
  });
}

function handleConfirm(){
    const query =route.query;
    query.bodyid = selectArr.value.join(";")
    const path = 'sdnew'
    router.replace({
        path,
        query
    })
    // const query = {idobject,refobject,relopeid,sdtype,headid,viewid,subviewid,subrefobject}

}
</script>

<style scoped>
</style>